package com.project;

import com.project.common.annotation.Service;
import com.project.common.pojo.ClassEntity;
import com.project.service.impl.DemoServiceImpl;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auther zhangwj
 * @date 2021/4/20 下午8:28
 */
public class RPCApplication {

    public static Map<String, Object> map = new HashMap<>();

    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        boolean flag = DemoServiceImpl.class.isAnnotationPresent(Service.class);
        if (flag) {
            Service service = DemoServiceImpl.class.getAnnotation(Service.class);
            Method[] methods = DemoServiceImpl.class.getMethods();
            for(Method method : methods){

            }

        }
    }


    public static <T> T getResult(String key, String methodName, List<Object> params, Class<T> tClass) throws InvocationTargetException, IllegalAccessException {
        Object object = map.get(key);
        Method[] methods = object.getClass().getMethods();
        for (Method method : methods) {
            if (method.getName().equals(methodName)) {
                Object o = method.invoke(object, params.toArray());
                return tClass.cast(o);
            }
        }
        return null;
    }
}
